<script src="{{ asset('js/jquery.min.js') }}"></script>
<script src="{{ asset('lib/layui/layui.js') }}"></script>
<script src="{{ asset('js/pager.js') }}"></script>
<script>
    //查看/添加

    function open_button(url,title,w=800,h=600){
        layer.open({
            type: 2,
            title: title,
            area: [w+'px', h+'px'],
            shadeClose: true, //点击遮罩关闭
            content: url,
        })
    }

    $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});

    layui.use(['table','form', 'layer', 'upload','element'], function(){
        var form = layui.form
            ,table = layui.table
            ,layer = layui.layer
            ,upload = layui.upload
            ,element = layui.element //Tab的切换功能，切换事件监听等，需要依赖element模块
            ,index = 0;

        //文件上传
        upload.render({
            elem: '#file_button',
            url: '{{route('file_upload')}}',
            auto: true, //选择文件后不自动上传
            accept: 'file', //普通文件
            size: 1024*200,
            before:function(){

            },
            choose: function(obj){
                $(".modal-save-btn").hide();
                obj.preview(function(index, file, result){
                    $("#file_preview").html(file.name);
                });
                index = layer.load();
            },
            done: function(data){
                if (data.code) {
                    $("#file_id").val(data.file_id);
                }else{
                    layer.msg(data.msg,{icon: 5,time:1000});
                }
                layer.close(index);
                $(".modal-save-btn").show();
            },
            error: function(){
                layer.msg('服务器错误！',{icon: 5,time:1000});
                $(".modal-save-btn").show();
            }
        });
    });
</script>
@yield('footer')
</body>
</html>